//
//  AddFriendsViewController.m
//  RingLetter
//
//  Created by dllo on 16/3/17.
//  Copyright © 2016年 FenglyNuo. All rights reserved.
//

#import "AddFriendsViewController.h"

@interface AddFriendsViewController ()

@property (retain, nonatomic) UITextField *friendName;
@property (retain, nonatomic) UIButton *addButton;

@end

@implementation AddFriendsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createSubView];
}


#pragma mark - createSubView
- (void)createSubView {
    self.friendName = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, kUIScreenWidth - 100, 50)];
    _friendName.layer.borderColor = [UIColor lightGrayColor].CGColor;
    _friendName.layer.borderWidth = 1;
    [self.view addSubview:_friendName];
    
    self.addButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.view addSubview:_addButton];
    _addButton.frame = CGRectMake(100, 200, kUIScreenWidth - 200, 50);
    [_addButton setTitle:@"add" forState:(UIControlStateNormal)];
    
    [_addButton addTarget:self action:@selector(addbuttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
}



- (void)addbuttonAction:(UIButton *)button {
    // 1.获取要添加好友的名字
    NSString *username = self.friendName.text;
    // 2.向服务器发送一个添加好友的请求
    //loginInfo字典,存当前用户的信息
    NSString *loginUsername = [[EaseMob sharedInstance].chatManager loginInfo][@"username"];
    NSLog(@"=====%@",loginUsername);
    NSString *message = [@"我是" stringByAppendingString:loginUsername];\
    
    // buddy 哥们的意思
    // message ： 请求添加好友的额外信息
    EMError *error =  nil;
    [[EaseMob sharedInstance].chatManager addBuddy:username message:message error:&error];
    if (error) {
        NSLog(@"添加好友有问题 %@",error);
        
    }else{
        NSLog(@"添加好友没有问题");
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
